﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true" CodeFile="Custom_List.aspx.cs" Inherits="Admin_Views_Custom_List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
    function reload() {
        $('#grid').datagrid("reload");
    }
    $(function () {
        $("#btn_AddCustom").click(function () {
            $.dialog({ title: "添加客户资料", content: 'url:views/custom/Custom_add.aspx', lock: false, max: false });
        });
        function getData() {
            var setting = $('#grid').datagrid("options");
            var result = DarkCRM.Models.Custom.GetPageing(parseInt(setting.pageSize, 10), setting.pageNumber);

            if (result.ErrorCode == 0)
                return result.Value;
            else
                alert(result.Name);
        }

        var lastIndex;
        $('#grid').datagrid({
            title: '客户列表',
            //iconCls: 'icon-save',
            width: 900,
            height: 500,
            nowrap: false,
            striped: false,
            collapsible: false, //是否显示收放按钮
            pageSize: 10,
            pageList: [10, 20],
            datafun: getData,
            sortName: 'ID', //初始排序字段
            sortOrder: 'desc',            //初始排序
            idField: 'ID',
            queryParams: { pid: 1234 }, //附加参数
            showFooter: true,
            remoteSort: true, //通过服务端排序
            singleSelect: true,
            columns: [[
					{ field: "DisplayName", title: '昵称', width: 150 },
                    { field: "CustomEmail", title: 'Email', width: 150 },
                    { field: "MobilePhone", title: '手机号码', width: 150 },
                    { field: "control", title: '操作', width: 150, formatter: function (value, rowData, rowIndex) {
                        return "<a href=\"javascript:production.del('" + rowData.ID + "')\">删除</a> | <a href=\"javascript:production.edit('" + rowData.ID + "')\">修改</a>"
                    }
                    }
				]],
            pagination: true,
            rownumbers: true,
            onClickRow: function (rowIndex) {
                if (lastIndex != rowIndex) {
                    //$('#grid').datagrid('endEdit', lastIndex);
                    //$('#grid').datagrid('beginEdit', rowIndex);
                }
                lastIndex = rowIndex;
            },
            onAfterEdit: function (rowIndex, rowData, changes) {
                var c = $.extend({ Passwords: 0, Level: -1 }, changes);
                if (c.Passwords == 0 && c.Level == -1)
                    return;
                DarkCRM.Admin.Update(rowData);
            }
        });
    });

    var production = {
        del: function (id) {
            dark.dialog.confrim("确定要删除该客户资料吗？", function () {
                DarkCRM.Models.Custom.DeleteCustom(id, { success: function () {
                    $('#grid').datagrid("reload");
                }
                });
            });
        },
    edit: function (id) {
        $.dialog.data('customID', "aaaa");
            $.dialog({ title: "修改客户资料", content: 'url:views/custom/Custom_add.aspx', lock: false, max: false });
        }
    };
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="btn_AddCustom">add</div>
<div id="grid"></div>
</asp:Content>

